package com.yanqu.road.server.manager.activity.seacraftsouthsea;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaActivityConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroup;
import com.yanqu.road.logic.bussiness.activity.SeacraftSouthSeaBusiness;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.server.CrossBaseServer;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.manager.union.activitygroup.Cross2UnionActivityGroupMgr;
import com.yanqu.road.utils.date.DateHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/20 16:38
 */
public class SeacraftSouthSeaConfigMgr{

    private static Logger logger = LogManager.getLogger(SeacraftSouthSeaConfigMgr.class.getName());

    private static Map<Integer, SeacraftSouthSeaActivityConfig> configMap = new ConcurrentHashMap<>();

    public static synchronized void reloadConfig(){
        logger.info("start reload Seacraft SouthSea activity config  start");
        String nowTimeStr = DateHelper.getCurrentDateTimeString();
        List<Integer> activityTypeList = new ArrayList<>();
        activityTypeList.add(eActivityType.SeacraftActivity.getValue());

        Map<Integer, ActivityInfo> activityInfoMap = ActivityBussiness.getOpenCrossRankActivityInfoMapByCrossServerId(activityTypeList, nowTimeStr, CrossBaseServer.getInstance().getServerId());
        for (ActivityInfo item : activityInfoMap.values()) {
            Map<Integer, UnionActivityGroup> groupMap = Cross2UnionActivityGroupMgr.getGroupMap(item.getActivityId());
            if (groupMap != null) {
                reloadConfig(item.getActivityId());
            }
        }
        logger.info("start reload Seacraft SouthSea activity config  end");
    }

    public static synchronized void reloadConfig(int activityId){
        List<Integer> activityIdList = new ArrayList<>();
        activityIdList.add(activityId);
        Map<String, ActivityConfig> activityConfigMap = ActivityBussiness.getActivityConfigMap(activityIdList).get(activityId);
        SeacraftSouthSeaActivityConfig southSeaActivityConfig = new SeacraftSouthSeaActivityConfig();
        southSeaActivityConfig.setShipList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaShipConfigList(activityId));
        southSeaActivityConfig.setGuessList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaGuessConfigList(activityId));
        southSeaActivityConfig.setFloorList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaFloorConfigList(activityId));
        southSeaActivityConfig.setBattleList(SeacraftSouthSeaBusiness.getSeacraftSouthSeaBattleConfigList(activityId));
        southSeaActivityConfig.parseConfig(activityConfigMap);
        configMap.put(activityId,southSeaActivityConfig);
    }


    public static Map<Integer, SeacraftSouthSeaActivityConfig> getConfigMap() {
        return configMap;
    }



}
